<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8"/>
  <title>Spring Boot and Easyui RBAC</title>

  <link rel="stylesheet" href="easyui/themes/bootstrap/easyui.css">
  <link rel="stylesheet" href="easyui/themes/icon.css">
  <link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="css/app.css">
  <script src="lib/jquery.min.js"></script>
  <script src="easyui/jquery.easyui.min.js"></script>
  <script src="easyui/locale/easyui-lang-zh_CN.js"></script>
  <script>
    $(function () {
      $.fn.tree.defaults.loadFilter = function (data, parent) {
        var opt = $(this).data().tree.options;
        var idFiled,
          textFiled,
          parentField;
        if (opt.parentField) {
          idFiled = opt.idFiled || 'id';
          textFiled = opt.textFiled || 'text';
          parentField = opt.parentField;

          var i,
            l,
            treeData = [],
            tmpMap = [];

          for (i = 0, l = data.length; i < l; i++) {
            tmpMap[data[i][idFiled]] = data[i];
          }

          for (i = 0, l = data.length; i < l; i++) {
            if (tmpMap[data[i][parentField]] && data[i][idFiled] != data[i][parentField]) {
              if (!tmpMap[data[i][parentField]]['children'])
                tmpMap[data[i][parentField]]['children'] = [];
              data[i]['text'] = data[i][textFiled];
              tmpMap[data[i][parentField]]['children'].push(data[i]);
            } else {
              data[i]['text'] = data[i][textFiled];
              treeData.push(data[i]);
            }
          }
          return treeData;
        }
        return data;
      };

      var menuTree = $("#menuTree");

      var center = $("body").layout("panel", "center");
      menuTree.tree({
        url: 'menus',
        parentField: 'parentId',
        onSelect: function (node) {
          center.panel('refresh', node.href).panel('setTitle', node.text);
        }
      });

      $.ajaxSetup({
        statusCode: {
          403: function (resp) {
            console.log(arguments)
            $.messager.alert("系统提示", "访问被拒绝！[" + resp.responseJSON.path + "]");
          },
          401: function () {
            $.messager.alert("系统提示", "登录超时!！", "info", function () {
              location.replace("/");
            });
          }
        }
      })
    });
  </script>
</head>
<body class="easyui-layout">
<div data-options="region:'north'" class="header">
  <h1 class="title">Spring Boot and Easyui RBAC</h1>
  <div class="info">
    <a th:text="${session.user.userName}">管理员</a>
    <a href="logout">注销</a>
  </div>
</div>
<div data-options="region:'west',iconCls:'fa fa-id-card-o'" title="导航" style="width: 150px;">
  <ul id="menuTree"></ul>
</div>
<div data-options="region:'center'" title="控制台">

</div>
<div data-options="region:'south'" class="footer">
  夏悸的教学视频第一季
</div>
</body>
</html>